Hi,
Your code won't work, your QSqlDatabase object is invalid.
Please take the time to look at the code example in QSqlDatabase's documentation as well as the example provided.
It' also discouraged to store database object like that locally. QSqlDatabase allows for easy connection handling without the need for these local copies.